import { DocumentChangeType, OrderByDirection, WhereFilterOp, SnapshotMetadata, SnapshotListenOptions, CollectionReference } from "firebase/firestore"; import { IDocumentRef } from "./field.types"; import { Query } from ".."; export interface IEntity { id: string; ref: IDocumentRef; toData(): Record; } export interface IQuery { where(property: keyof T, op: WhereFilterOp, value: any): IQuery; orderBy(property: keyof T, sort?: OrderByDirection): IQuery; limit(amount: number): IQuery; startAt(...fieldValues: any[]): IQuery; startAfter(...fieldValues: any[]): Query; endAt(...fieldValues: any[]): Query; endBefore(...fieldValues: any[]): Query; onSnapshot(onNext: (snapshot: IQuerySnapshot) => void, onError?: (error: Error) => void): () => void; get(): Promise>; } export interface IQuerySnapshot { docs: T[]; size: number; empty: boolean; query: IQuery; metadata: SnapshotMetadata; forEach: (callback: (doc: T, index: number) => void) => void; docChanges: (opts?: SnapshotListenOptions) => DocumentChange[]; } export interface IDocumentSnapshot { doc: T; exists: boolean; ref: IDocumentRef; metadata: SnapshotMetadata; } export interface ICollection { native: CollectionReference; path: string; parent?: IDocumentRef

| null; query: () => IQuery; create: (entity: T) => Promise; update: (entity: T) => Promise; doc: (id: string) => IDocumentRef; get: (id: string) => Promise; find: (query?: ICollectionQuery) => Promise; remove: (id: string) => Promise; } export interface DocumentChange { doc: T; type: DocumentChangeType; newIndex: number; oldIndex: number; } export interface ICollectionConfig { name: string; } declare type WhereQuery = [keyof T, WhereFilterOp, any]; declare type OrderByQuery = [keyof T, OrderByDirection?]; declare type StartAtQuery = T | any; declare type StartAfterQuery = T | any; declare type EndAtQuery = T | any; declare type EndBeforeQuery = T | any; export interface ICollectionQuery { where?: WhereQuery[]; orderBy?: OrderByQuery[]; limit?: number; startAt?: StartAtQuery; startAfter?: StartAfterQuery; endAt?: EndAtQuery; endBefore?: EndBeforeQuery; } export interface ISubCollectionConfig extends ICollectionConfig { entity: new () => IEntity; } export {};